﻿using LumiSoft.Net.IMAP;
using ServiceStack.DataAnnotations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;


namespace EmailClient.Model
{
    enum StatusLetter
    {
        Incoming,   //0  
        Sent,       //1
        Draft,      //2
        Spam,       //3
        Trash       //4
    }

    public class Letter
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        public int StatusId { get; set; }
        public int FolderId { get; set; }
        public string MessageId { get; set; }
        public long UID { get; set; }
        public DateTime DepartureDate { get; set; }
        public bool Read { get; set; }
        [CustomField("CHAR(500)")]
        public string FromSent { get; set; }

        [CustomField("CHAR(500)")]
        public string ToSent { get; set; }
        public string CC { get; set; }
        public string Bcc { get; set; }

        [CustomField("CHAR(500)")]
        public string Subject { get; set; }        

        [CustomField("CHAR(100)")]
        public string Email { get; set; }

        public string BodyAsText { get; set; }      
        
        public string BodyAsHTML { get; set; }
        
        [Required]
        [References(typeof(EmailAccount))]
        public int AccountId { get; set; }

        [Reference]
        public EmailAccount Account { get; set; }

        [Reference]
        public List<Attachment> Attachments { get; set; }

        #region IDataErrorInfo Members

        //[Ignore]
        //public string Error
        //{
        //    get { return null; }
        //}

        //[Ignore]
        //public string this[string columnName]
        //{
        //    get
        //    {
        //        if (columnName == "ToSent")
        //        {                    
        //            if (this.ToSent != null)
        //            {
        //                string pattern = @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
        //                Regex rgx = new Regex(pattern);
        //                if (!rgx.IsMatch(this.ToSent)) 
        //                    return "Не верно указан адрес получателя!";
        //            }
        //            else
        //            {
        //                return "Не указан адрес получателя!";
        //            }
        //        }

        //        return null;
        //    }
        //}

        #endregion
      
    }
}
